package com.tjsinfo.tjsoa.address.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.address.common.TAddresslistCommon;
import com.tjsinfo.tjsoa.address.common.TAddresslistCommonManager; 
import com.tjsinfo.tjsoa.common.DayFormat;


public class CommonSaveAction extends Action {
	
    TAddresslistCommonManager addresslistCommonManager;
	
	public TAddresslistCommonManager getAddresslistCommonManager() {
		return addresslistCommonManager;
	}

	public void setAddresslistCommonManager(
			TAddresslistCommonManager addresslistCommonManager) {
		this.addresslistCommonManager = addresslistCommonManager;
	}
	
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			TAddresslistCommon tso=new TAddresslistCommon();
			tso.setChineseName(request.getParameter("chinese_name"));
			tso.setBeforeName(request.getParameter("before_name"));
			tso.setEnglishName(request.getParameter("english_name"));
			tso.setOfficeship(request.getParameter("officeship"));
			Date date=new Date();
			String birthday=request.getParameter("birthday");
			if(birthday!=null && !birthday.equals("")){
				tso.setBirthday(DayFormat.getDate(birthday, DayFormat.FormatDay1));
			}
			tso.setSex(request.getParameter("sex"));
			tso.setDepatment(request.getParameter("depatment"));
			tso.setPostCode(request.getParameter("post_code"));
			tso.setFaxNo(request.getParameter("fax_no").replace("－", "-"));
			tso.setMobile(request.getParameter("mobile").replace("－", "-"));
			tso.setOfficePhone(request.getParameter("office_phone").replace("－", "-"));
			tso.setFamilyPhone(request.getParameter("family_phone").replace("－", "-"));
			tso.setEmail(request.getParameter("email"));
			tso.setCompany(request.getParameter("company"));			
			tso.setComAddress(request.getParameter("com_address"));
			tso.setFamilyAddress(request.getParameter("family_address"));
			tso.setAlt(request.getParameter("alt"));
			String inlineNo = request.getParameter("inline_no") + ",";
			tso.setInlineNo(inlineNo);
			addresslistCommonManager.save(tso);

			
			return mapping.findForward("success");
		}catch (Exception e) {
			return mapping.findForward("failure");
		}
	}
}